import { onBeforeUnmount, onMounted,reactive } from "vue";

export default function () {
  let point = reactive({
    x: 0,
    y:0
  })

  function savePoint(event) {
    point.x = event.pageX;
    point.y = event.pageY;
    console.log(point.x,point.x);
  }

  onMounted(() => {
    window.addEventListener('click', savePoint)
  });

  onBeforeUnmount(() => {
    // 一个点击事件可能有多个回调，因此要指明移除哪个回调
    window.removeEventListener('click', savePoint)
  });

  return point;
}